<?php /* PROJECTS $Id: vw_idx_proposed.php,v 1.22.6.3 2006/11/19 16:01:34 gregorerhardt Exp $ */
GLOBAL $AppUI, $projects, $pstatus, $psfilter;

$show_all_projects = $psfilter == P_ALL;

$perms =& $AppUI->acl();
$df = $AppUI->getPref('SHDATEFORMAT');
	// Let's check if the user submited the change status form

$canChangeStatus = $AppUI->user_type <= 5 && $psfilter != P_TEMPLATE;
?>

<form action='index.php' method='get'>
<table id="<?=$psfilter?>" width="100%" border="0" cellpadding="3" cellspacing="0" class="list">
<tr class="clickable">
	<th width="50px" nowrap="nowrap" id="project_color_identifier" onclick="setMode(this)">
		<?=$AppUI->_('Color')?>
	</th>
	<th nowrap="nowrap" id="project_code" onclick="setMode(this)">
		<?=$AppUI->_('Reference Code')?>
	</th>
	<th nowrap="nowrap" id="project_name" onclick="setMode(this)">
		<?=$AppUI->_('Reference Name')?>
	</th>
	<th nowrap="nowrap" id="company_name" onclick="setMode(this)">
		<?=$AppUI->_('Customer')?>
	</th>
	<th width="70px" nowrap="nowrap" id="project_start_date" onclick="setMode(this)">
		<?=$AppUI->_('Type')?>
	</th>
	<th width="70px" nowrap="nowrap" id="project_end_date" onclick="setMode(this)">
		<?=$AppUI->_('Shipping Type')?>
	</th>
	<th width="70px" nowrap="nowrap" id="project_actual_end_date" onclick="setMode(this)">
		<?=$AppUI->_('Shipper')?>
	</th>
	<th nowrap="nowrap" id="task_log_problem" onclick="setMode(this)">
		<?=$AppUI->_('Quotation Name')?>
	</th>
	<th width="32px" nowrap="nowrap" id="user_username" onclick="setMode(this)">
		<?=$AppUI->_('Remarks')?>
	</th>
	<? if($show_all_projects) { ?>
	<th width="60px" nowrap="nowrap"><?=$AppUI->_('Status')?></th>
	<? } ?>
<? if ($canChangeStatus) { ?>
	<th width="20px" nowrap="nowrap" class="last">
		<?=$AppUI->_('Set')?>
	</th>
<? } ?>
</tr>

<?php
$none = true;
$np = 1;
//showFVar($projects);
foreach ($projects as $row) {
	if (! $perms->checkModuleItem('projects', 'view', $row['project_id'])) {
		continue;
	}
	if ($show_all_projects || $row["project_status"] == $psfilter) {
		$none = false;
		$start_date = intval( @$row["project_start_date"] ) ? new CDate( $row["project_start_date"] ) : null;
		$end_date = intval( @$row["project_end_date"] ) ? new CDate( $row["project_end_date"] ) : null;
		$actual_end_date = intval( @$row["project_actual_end_date"] ) ? new CDate( $row["project_actual_end_date"] ) : null;
		$style = (( $actual_end_date > $end_date) && !empty($end_date)) ? 'style="color:red; font-weight:bold"' : '';

		$s = '<tr class="'.($np % 2 == 1 ? 'first' : 'second').'">'; $np++;
		$s .= '<td>'.
				'<div align="center" style="width: 100%; border: outset #eeeeee 1px;background-color:#' . $row["project_color_identifier"] . '">';
		$s .= '<font color="' . bestColor( $row["project_color_identifier"] ) . '">'
			. sprintf( "%.1f%%", $row["project_percent_complete"] )
			. '</font>';
		$s .= '</div></td>';

		$s .= '<td class="clickable" onclick="viewProject('.$row["project_id"].')">'.htmlspecialchars($row["project_name"], ENT_QUOTES ).'</td>';
		$s .= '<td class="clickable" onclick="viewProject('.$row["project_id"].')">'.htmlspecialchars($row["project_code"], ENT_QUOTES ).'</td>';

		if ($perms->checkModuleItem('companies', 'access', $row['project_company'])) {
			$s .= '<td class="clickable" onclick="Company('.$row["project_company"].').show()" title="' . htmlspecialchars( $row["company_description"], ENT_QUOTES ) . '">' . htmlspecialchars( $row["company_name"], ENT_QUOTES ) . '</td>';
		} else {
			$s .= '<td>'.htmlspecialchars( $row['company_name'], ENT_QUOTES ).'</td>';
		}

		$s .= '<td align="left">'. $row['project_rtype'] .'</td>';
		$s .= '<td align="left">'. $row['project_shipping_type_name'] .'</td>';
		$s .= '<td align="left">'. $row['project_shipper_name'] .'</td>';
		$s .= '<td align="center">' . 'test' . '</td>';
		$s .= '<td align="center">' . $row['project_description']. '</td>';
		if ($show_all_projects) {
			$s .= '<td align="center" nowrap="nowrap">';
			$s .= $pstatus[$row["project_rstatus"]];
			$s .= '</td>';
		}

		if ($canChangeStatus) {
			$allow = !$show_all_projects || $row["project_status"] != P_TEMPLATE ? '' : 'disabled = "true"';
			$s .= '<td align="center">';
			if ($perms->checkModuleItem('projects', 'edit', $row['project_id']))
				$s .= '<input type="checkbox" name="project_id[]" value="'.$row["project_id"].'" '.$allow.'/>';
			else
				$s .= '&nbsp;';
		}

		$s .= '</tr>';
		echo $s;
	}
}
if ($none) {
	echo '<tr><td colspan="10">' . $AppUI->_( 'No projects available' ) . '</td></tr>';
} else {
	if ($canChangeStatus) {
?>
<tr>
	<td colspan="100%" align="right">
		<?php
			echo "<input type='submit' class='button' value='".$AppUI->_('Update status')."' />";
			echo "<input type='hidden' name='update_project_status' value='1' />";
			echo "<input type='hidden' name='m' value='projects' />";
			echo arraySelect( $pstatus, 'project_status', 'size="1" class="text"', P_ACTIVE, true );
		?>
	</td>
</tr>
<?
	}
}
?>
</table>
</form>
